﻿using System;
using Viettel.VOFFICE.DAO.Helpers;
using Viettel.VOFFICE.DAO.Models;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using Viettel.VOFFICE.DAO.Enums;


namespace Viettel.VOFFICE.Web.Models
{
    public class MetaDataModel : BaseModel
    {
        // Khai báo các giá trị db
        public int Id { get; set; }
        public string Name { get; set; }
        public short Type { get; set; }
        public string TypeName { get; set; }
        public bool? IsActive { get; set; }
        public int? ParentId { get; set; }
        public string ParentName { get; set; }
        public DateTime CreatedAt { get; set; }
        public DateTime UpdatedAt { get; set; }
        public Guid? CreatorId { get; set; }
        //Khởi tạo hàm không đối số

        public MetaDataModel()
        {
            CreatedAt = DateTime.Now;
            UpdatedAt = DateTime.Now;
            IsActive = true;
        }

        public MetaDataModel(MetaData metaData)
        {
            Id = metaData.Id;
            Name = metaData.Name;
            Type = metaData.Type;
            ParentId = metaData.ParentId;
            IsActive = metaData.IsActive;
            CreatedAt = metaData.CreatedAt;
            CreatorId = metaData.CreatorId;
            UpdatedAt = metaData.UpdatedAt;
            TypeName = EnumHelper<MetaDataType>.GetStringValue((MetaDataType)metaData.Type);
            //tự quan hệ:D
            if (metaData.ParentId != null && metaData.ParentId >0)
            {
                // listCollection = metadata1;
                // item = metadata2;
                ParentName = metaData.MetaData2.Name;
            }
        }

        
    }
}